package com.sinoglobal.ningxia.activity.shop;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.activity.base.BaseActivity;
import com.sinoglobal.ningxia.beans.MyGoodVo;
import com.sinoglobal.ningxia.downdata.imp.RemoteImpl;
import com.sinoglobal.ningxia.frame.FlyApplication;
import com.sinoglobal.ningxia.http.Code;
import com.sinoglobal.ningxia.http.ConnectionUtil;

import net.tsz.afinal.FinalBitmap;

/**
 * 
 * @author zbl
 * @createdate 2014-7-17 下午5:38:30
 * @Description:展示用现金以购买的物品
 */
public class CashPurchasedActivity extends BaseActivity {
	private ImageView shoppingImg;// 活动的img
	private TextView mallShopActivityName;// 活动名称
	private TextView mallShopActivityDate;// 活动的有效期
	private TextView goodsContent;// 活动的详细介绍
	private Button goodsCode;// 购买
	private Intent intent;
	private String goodsId;
	private String bogId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		isTemplate = true;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mallshop_shopping_cash);
		titleView.setText(R.string.shoping_goodsName);
		openChenJInShi();//开启沉浸式
		intent = getIntent();
		bogId = intent.getStringExtra("bog_id");
		goodsId = intent.getStringExtra("goods_id");
		init();// 初始化控件
		loadInfo();// 从网络获取数据
	}

	public void init() {
		shoppingImg = (ImageView) findViewById(R.id.shopping_img);
		mallShopActivityName = (TextView) findViewById(R.id.mallshop_goodsName);
		mallShopActivityDate = (TextView) findViewById(R.id.mallshop_goods_date);
		goodsContent = (TextView) findViewById(R.id.goods_content);
		goodsCode = (Button) findViewById(R.id.goods_code);
		// 设置图片的宽高
		int width = FlyApplication.widthPixels;
		int height = width / 2;
		shoppingImg.setLayoutParams(new LinearLayout.LayoutParams(width, height));
	}

	// 加载活动信息
	private void loadInfo() {
		new ItktAsyncTaskWithDialog<Void, Void, MyGoodVo>(getString(R.string.loading), true, true) {

			@Override
			public com.sinoglobal.ningxia.beans.MyGoodVo before(Void... params) throws Exception {
				return RemoteImpl.getInstance().getMyGoodActivity(bogId, goodsId);
			}

			@Override
			public void after(com.sinoglobal.ningxia.beans.MyGoodVo result) {
				if (result != null) {
					if (Code.CODE_SUCCESS != result.getCode()) {
						showShortToastMessage(result.getMessage());
					} else {
						// 填充数据到布局上
						mallShopActivityName.setText(result.getAct_name());
						FinalBitmap fb = FinalBitmap.create(CashPurchasedActivity.this);
						fb.configLoadfailImage(R.drawable.default43);
						fb.configLoadingImage(R.drawable.default43);
						String URL = ConnectionUtil.localUrl + result.getAct_img();
						fb.display(shoppingImg, URL);
						mallShopActivityDate.requestFocus();// 需要焦点
						mallShopActivityDate.setText(result.getAct_start() + "至" + result.getAct_end());
						goodsContent.setText(result.getAct_content());
						goodsCode.setText(result.getAct_code());
						goodsCode.setBackgroundResource(R.drawable.bg_enentitem_btn);

					}
				}

			}

			@Override
			public void exception() {

			}

		}.execute();

	}

}
